import { Ast, Visitor, createRootAst } from "./ast";
export interface MineMoney{
    count?: number;
}
export function getMineMoney() {
    const ctx: MineMoney = {}
    const visitor = new MineMoneyVisitor()
    while(typeof ctx.count === 'undefined'){
        const root = createRootAst()
        root.visit(visitor, ctx)
        sleep(1000)
    }
    return ctx.count;
}

export class MineMoneyVisitor implements Visitor<MineMoney> {
    visitNode(node: Ast, ctx: any) {
        if (node.className === `android.view.ViewGroup`) {
            this.visitViewGroup(node, ctx)
        }
        node.children.map(child => child.visit(this, ctx))
    }
    visitViewGroup(node: Ast, ctx: MineMoney) {
        if (node.children.length === 2) {
            const key = node.children[0]
            const val = node.children[1];
            if (key.text === `快币(充值)`) {
                ctx.count = parseInt(val.text)
            }
        }
        node.children.map(child => child.visit(this, ctx))
    }
}